from django.db import models


from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    mobile = models.CharField(max_length=11, unique=True)

    class Meta:
        db_table = 'diancan_user'
        verbose_name = '用户表'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.username


class Order(models.Model):
    status_choices = (
        (0, '未接单'),
        (1, '未接单'),
        (2, '已接单'),
        (3, '超时取消'),
    )
    subject = models.CharField(max_length=150, verbose_name="订单标题")
    out_trade_no = models.CharField(max_length=64, verbose_name="订单号", unique=True)
    order_status = models.SmallIntegerField(choices=status_choices, default=0, verbose_name="订单状态")
    pay_time = models.DateTimeField(verbose_name="下单时间", auto_now_add=True)
    total_amount = models.DecimalField(max_digits=8, decimal_places=2, verbose_name="订单总价",default=0)
    name = models.CharField(max_length=150,verbose_name="下单用户",default='匿名用户')

    @property
    def order_type(self):
        return self.get_order_status_display()

